/*This program will produce the results for Table 6*/


clear all

set mem 50m

/*Input directory here*/
cd "C:\Users\bond10\Desktop\RA\Test Scores\Paper\replication files"

use ECLSbondlang.dta, clear

set more off


/*apply normalization*/
replace readspring3 = readspring3/180
replace readfallk = readfallk/180
replace readspringk = readspringk/180
replace readspring1 = readspring1/180

local flcontrols = "hispanic asian other birthweight missingbirthweight female books books2 missingbooks momover30 teenmom missingmombirth ses missingses wic missingwic"

/*Columns 1 and 2*/
scalar B1 = 1.65087720125322E-19
scalar B2 = 9.94691483930691
scalar B3 = -26.4577999746567
scalar B4 = -9.81183841582317
scalar B5 = 26.2783331141084
scalar B6 = 82.9402686962257
scalar k = 0.119479
scalar N1 = 0.186615831283162-15
***********************************

foreach x in fallk springk spring1 spring3         {
gen transform`x' = B1*(read`x' + k) + B2*(read`x' + k)^2 + B3*(read`x' + k)^3 + B4*(read`x' + k)^4 + B5*(read`x' + k)^5 + B6*(read`x' + k)^6 - N1
                                                       }

/*Normalize transformed scores by grade taken (weights)*/

foreach x in fallk springk spring1 spring3  {
qui: summ transform`x' [aweight=weights]
scalar mn = r(mean)
scalar stnd = r(sd)
qui: gen transform`x'std = (transform`x'-mn)/stnd
qui: reg transform`x'std black hispanic asian other [pweight=weights], robust
est sto A`x' 
 }


foreach x in fallk springk spring1 spring3  {										
qui: reg transform`x'std black age`x' `flcontrols' [pweight=weights], robust
est sto B`x'
}



drop transformfallk-transformspring3std

/*Columns 3 and 4*/
scalar B1 = 2.55881980375649
scalar B2 = 10.8705267018669
scalar B3 = -47.4535179662484
scalar B4 = -4.38830943412748
scalar B5 = 102.957466858085
scalar B6 = 12.5181405382265
scalar k = 0.1450721
scalar N1 = -15+0.639947363155228
***********************************

foreach x in fallk springk spring1 spring3         {
gen transform`x' = B1*(read`x' + k) + B2*(read`x' + k)^2 + B3*(read`x' + k)^3 + B4*(read`x' + k)^4 + B5*(read`x' + k)^5 + B6*(read`x' + k)^6 - N1
                                                       }

/*Normalize transformed scores by grade taken (weights)*/

foreach x in fallk springk spring1 spring3  {
qui: summ transform`x' [aweight=weights]
scalar mn = r(mean)
scalar stnd = r(sd)
qui: gen transform`x'std = (transform`x'-mn)/stnd
qui: reg transform`x'std black hispanic asian other [pweight=weights], robust
est sto C`x' 
 }


foreach x in fallk springk spring1 spring3  {										
qui: reg transform`x'std black age`x' `flcontrols' [pweight=weights], robust
est sto D`x'
}

/*end normalization*/
replace readspring3 = readspring3*180
replace readfallk = readfallk*180
replace readspringk = readspringk*180
replace readspring1 = readspring1*180

est tab Afallk Aspringk Aspring1 Aspring3, b se keep(black)
est tab Bfallk Bspringk Bspring1 Bspring3, b se keep(black)
est tab Cfallk Cspringk Cspring1 Cspring3, b se keep(black)
est tab Dfallk Dspringk Dspring1 Dspring3, b se keep(black)
